import partie3 as p3
import numpy as np
import matplotlib.pyplot as mp
from scipy.misc import imread
A=mp.imread("youtube.png")

print A.shape


def min(x,y):
    if(x<= y):
        min=x
    else:
        min=y
    return min




def compress_matrix(M,k):
    (Ql,S,Qr)=p3.diagonale_convergence_optimized(M,10)
    for i in range(M.shape[0]-k):
        S[k+i,k+i]=0

    return np.dot(np.dot(Ql,S),Qr)




A[0:200,0:200,0]=compress_matrix(A[0:200,0:200,0],20)
A[0:200,0:200,1]=compress_matrix(A[0:200,0:200,1],20)
A[0:200,0:200,2]=compress_matrix(A[0:200,0:200,2],20)






mp.imshow(A)
mp.savefig('youtube-20.png')
